package com.janlei.acc.prototype;

import java.io.Serializable;
import java.util.Objects;

/**
 * 原型模式
 */
public class PrototypeStu {

}

class Square extends Shape {

    public Square() {
        super();
    }

    public Square(String name, String shape) {
        super(name, shape);
    }
}

class Func {
    private final String paint;

    public Func(String paint) {
        this.paint = paint;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Func func = (Func) o;

        return Objects.equals(paint, func.paint);
    }

    @Override
    public int hashCode() {
        return paint != null ? paint.hashCode() : 0;
    }

    @Override
    public String toString() {
        return "Func{" +
                "paint='" + paint.hashCode() + '\'' +
                '}';
    }
}

class Circle extends Shape {
    private final Func func = new Func("Paint");

    public Circle() {
        super();
    }

    public Circle(String name, String shape) {
        super(name, shape);
    }

    @Override
    public String toString() {
        return "Circle{" + super.toString() +
                ", func=" + func.hashCode() +
                '}';
    }
}

class Shape implements Cloneable, Serializable {
    private String name;
    private String shape;

    public void deepClone() {
    }

    @Override
    protected Shape clone() {
        Shape shape = null;
        try {
            shape = (Shape) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return shape;
    }

    @Override
    public String toString() {
        return "Shape{" +
                "name='" + name + '\'' +
                ", shape='" + shape + '\'' +
                '}';
    }

    public Shape() {
    }

    public Shape(String name, String shape) {
        this.name = name;
        this.shape = shape;
    }
}